# coding:utf-8

import os

def create_package(path):
    if os.path.exists(path):
        raise Exception('%s 已经存在不可创建' % path)
    os.makedirs(path)
    init_path = os.path.join(path,'__init__.py')
    f = open(init_path,'w')
    f.write('# coding:utf-8\n')
    f.close()

class Open(object):
    def __init__(self,path,mode='r+',is_return=True):
        self.path = path
        self.mode = mode
        self.is_return = is_return

    def write(self,message):
        with open(self.path,mode=self.mode,encoding='utf-8') as f:
            message = '%s\n' % message
            f.write(message)

    def read(self,is_strip =True):
        result = []
        with open(self.path,mode = self.mode,encoding='utf-8') as f:
            data = f.readlines()
            for line in data:
                if is_strip == True:
                    temp = line.strip()
                    if temp != "":
                        result.append(temp)
                else:
                    if line != '':
                        result.append(line)
            return result


if __name__ == '__main__':
    current_path = os.getcwd()
    print(current_path)
    # path = os.path.join(current_path,'test1')
    # create_package(path)
    open_path = os.path.join(current_path,'b.txt')
    o = Open(open_path,mode='r+')
    o.write('这是一个测试')
    o.write('5462')
    result = o.read(is_strip=False)
    print(result)


